'Muestra la secuencia de Intro o de Final

selectScene()
STOP

#INCLUDE <putchars.bas>
#INCLUDE <scroll.bas>
#INCLUDE <winscroll.bas>
#INCLUDE <retrace.bas>
#INCLUDE <memcopy.bas>
#INCLUDE  <fastplot.bas>
#INCLUDE "sprites/SPIntro.spr.bas"
#INCLUDE "sprites/naveintro.spr.bas"
#INCLUDE once "utils/Doublesizeprint.bas"
#INCLUDE "sprites/sky.spr.bas"
#INCLUDE "sprites/hojas.bas"
#INCLUDE "VarComp.bas" 
#INCLUDE "utils/muthur.bas"
#INCLUDE "Sonido.bas" 
#INCLUDE "Panel.bas"

Dim PX, PY As UByte
Dim Frame As UByte
Dim ind As UINTEGER
Dim ininave As UBYTE
Dim inimens As UINTEGER
Dim i,j As UBYTE
Dim textofinal As UBYTE

'Seleciona escena
Sub selectScene()
    SilenciarAY()
    If ending=1 Then
        BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS
        textofinal=0
        introScene()
    Else
        endScene()
    End If
END Sub

'Pinta las estrellas del array stars
Sub pintaEstrellas()
    Dim i As UBYTE
    For i=0 To 30
        fastPlotXOR(stars(i,0),stars(i,1))
    Next i
END Sub

'Mueve las estrellas
Sub mueveEstrellas()
    Dim i As UBYTE
    For i=0 To 30
        stars(i,1)=stars(i,1)-1
    Next i
END Sub

'Escena de Intro
Sub introScene()
    Dim i As UINTEGER
    Dim j As UBYTE

    POKE (UInteger 23606, @spaceFnt-256)     

    PutChars(14,8,2,8,@nave_izq(0))
    PutChars(16,8,2,8,@nave_der(0))
    paint(14,8,2,8,7)
    pintaEstrellas()
    bP=bP+4

    over 1     
    For i=0 To 350
        pause 1
        pintaEstrellas()    
        mueveEstrellas()    
        waitretrace
        pintaEstrellas()    
        pause 2
        If  i mod 50 Then     
            PRINT AT 16,16;chr$(125); 
            PRINT AT 16,15;chr$(125);
        Else
            PRINT AT 16,16;chr$(125);
            PRINT AT 16,15;chr$(125); 
        End If
        If i=0 Then
            Printtxt("        ISS ICARUS II            ",3,-1)
        End If
        If i=30 Then
            Printtxt(" 4M light years from Earth       ",3,-1)
        End If
        If i=70 Then
            Printtxt("                                 ",3,-1)
        End If     
        If i=80 Then
            snd128(0)
            Printtxt(" ALICE AI Activated              ",2,-1)
        End If
        If i=110 Then
            Printtxt(" Waking up from cryostasis       ",2,-1)
        End If
        If i=170 Then
            snd128(2)
            Printtxt(" Incoming transmission           ",2,-1)
        End If
        If i=200 Then
            snd128(0)
            Printtxt(" Matt! Im .,.,-?!...ped Help!    ",1,-1)
        End If
        If i=250 Then
            Printtxt(" Lars! What? I dont understand you",0,-1)
        End If
        If i=300 Then
            Printtxt(" I will find you sister!          ",0,-1)
        End If
    Next i

    cls: OVER 0
    For i=0 To 100
        fastPlotXOR(stars(i,0),stars(i,1))
    Next i

    Printtxt(" Approaching To Arboreto        ",2,1)

    PRINT AT 0,3;chr$(123):PRINT AT 0,5;chr$(40)
    PRINT AT 0,8;ink 5; chr$(126) 
    PRINT AT 0,22;ink 2; chr$(127); ink 7; " ";chr$(40);"  ";chr$(125);
    PRINT AT 0,13;chr$(91);chr$(94);chr$(60);chr$(61);chr$(64)
    PRINT AT 1,13;chr$(93);chr$(94);chr$(95);chr$(95);chr$(96);chr$(92);
    PRINT AT 0,18;chr$(59);  
        
    PRINT AT 0,3;chr$(123):PRINT AT 0,5;chr$(40)
    PRINT AT 0,8;ink 5; chr$(126) 
    PRINT AT 0,22;ink 2; chr$(127); ink 7; " ";chr$(40);"  ";chr$(125);
    PRINT AT 7,2;ink 6; chr$(127); ink 7: PRINT AT 7,26;chr$(123)
    PRINT AT 9,28;ink 3; chr$(126); ink 7;                
    PRINT AT 12,0; CHR$(125)
    PRINT AT 15,30;ink 4; chr$(127); ink 7;    
    OVER 1: PRINT AT 1,16;chr$(123): OVER 0    
    paint(13,0,6,2,4)     
    paint(14,0,4,1,33)     
    paint(15,1,2,1,33)     

    For j=0 To 17
        For i=0 To 7
            POKE (UInteger 23606, @spaceFnt-255+i)
            print at bP-5-j,16; chr$(36)    
            print at bP-4-j,16; chr$(37)
            print at bP-3-j,16; chr$(38)    
            pause 2
        Next i
        If j=12
            Printtxt(" Hold on! we are going to land    ",2,1):
        End If
    Next j 
    POKE (UInteger 23606, @spaceFnt-256)     
        
    PX=0
    PY=9
       
    Principal()
    bP=bP-4
        
    ImprimePanel()
    MODRun=MOD_JUE
END Sub

'Escena de Fin
Sub endScene()
    ending=0     
    textofinal=1
    PX=0
    PY=15
    epilogue()
    bP=bP+4
    ink 7
    Principal()
    MODRun=MOD_MEN
END Sub

'Escena de Epílogo
Sub epilogue()
    pantalla=47
    paint(12,21,1,2,4+64): paint(13,21,1,2,4)     
    Printtxt("I have found an energy cell!!(",0,1): pause 100
    Printtxt("I know how to adapt it for (((",1,1): pause 100
    Printtxt("my spaceship( Come with me!!  ",1,1): pause 100
        
    PRINT USR IMPRPANT     
        
    putCharsOverMode(19,12,ANCHO,ALTO,3,@Matt_parado_der_mask(0,0))
    putCharsOverMode(19,12,ANCHO,ALTO,2,@Matt_parado_der(0,0)) 
    paint(20,13,1,1,57)     
    putCharsOverMode(23,12,ANCHO,ALTO,3,@Matt_parado_izq_mask(0,0))    
    putCharsOverMode(23,12,ANCHO,ALTO,2,@Matt_parado_izq(0,0))    
    paint(23,13,1,1,59)     
    putChars(23,13,1,1,@Matt_lars)
    PutChars(21,14,2,2,@tiles(47,0))
    paint(21,14,1,2,4+64): paint(22,14,1,2,4)     
    Printtxt("You)ve discovered a new energy",2,1): pause 100
    Printtxt("source( Those crystals may (((",2,1): pause 100
    Printtxt("solve Earth)s energy needs!!  ",2,1): pause 300
    PRINT USR TRANSIT 
END Sub

'Parte principal de la escena de Intro
Sub Principal() 
    snd128(6)
    CLS
    Frame=0
    ininave=80
    inimens=ininave+50
    putChars(0,16,8,6,@hojas(0))
    putChars(8,16,8,6,@hojas(0))
    putChars(16,16,8,6,@hojas(0))
    putChars(24,16,8,6,@hojas(0))
    putChars(5,3,5,2,@skyNube1(0))
    putChars(15,4,5,2,@skyNube1(0))
    putChars(22,5,5,2,@skyNube1(0))
    putChars(12,6,3,1,@skyNube2(0))
    putChars(20,7,3,1,@skyNube2(0))
    paint(0,17,32,5,%00000100)     
    ind=0     
        
    PRINT AT 0,3;chr$(123):PRINT AT 0,5;chr$(40)
    PRINT AT 0,8;ink 5; chr$(126) 
    PRINT AT 0,22;ink 2; chr$(127); ink 7; " ";chr$(40);"  ";chr$(125);
    For i=0 To 50
        fastPlotXOR(stars(i,0),172+stars(i,1) mod 19)
    Next i

    Do
        waitretrace
        paint(0,17,32,5,%00000100)     
        mueveNave()
        ind=ind+1

        If textofinal=0 Then     
                
            If ind = inimens Then
                Printtxt(" ALICE did you heard that?    ",0,-1)
                snd128(5)    
            End If

            If ind = inimens+70 Then
                Printtxt("Hull breach! Emergency Landing!",2,-1)
                snd128(2)
            End If

            If (ind> inimens+70) And ind mod 10 = 1 Then     
                putCharsOverMode(PX-1,PY,3,2,2,@nave_mask(Frame,0))    
                putCharsOverMode(PX,PY,3,2,2,@nave_mask(Frame,0))
                PY=PY+1
                If PY>15 Then
                    snd128(5)    
                    Dim i,j As UBYTE
                    For j=0 To 3
                        For i=1 To 7
                            paint(0,0,32,22,7-i)     
                            pause 3     
                        Next i
                    Next j 
                        
                    Printtxt(" Your equipment is scattered  ",2,-1)
                    PAUSE 100
                    For i=0 To 3
                        PutChars(9+i*4,19,2,2,@tiles(36+i,0))
                        PaintData(9+i*4,19,2,2,@tiles_attr(36+i,0)) 
                        snd128(0)
                        pause 30
                    Next i
                    PAUSE 100
                    Printtxt(" You must To find it!         ",2,-1)
                    PAUSE 100
                    paint(0,bP-2,1,2,5)     
                    paint(0,bP-1,1,2,4)
                    RETURN
                End If
            End If
        Else     
                
            If ind= inimens+30 Then
                doubleSizePrint(5, 14, "THE END")
            End If
            If ind> inimens+230 Then
                If ind mod 5 = 0 Then     
                    putCharsOverMode(PX,PY,3,2,2,@nave_mask(Frame,0))     
                    putCharsOverMode(PX-1,PY,3,2,2,@nave_mask(Frame,0))     
                    PY=PY-1
                    If PY=7     
                        For i=0 To 7
                            paint(0,0,32,24,7-i)
                            PAUSE 8
                        Next 
                        snd128(0)
                        SilenciarAY()
                        PAUSE 100
                        RETURN
                    End If
                End If
            End If   
            If ind = inimens Then
                Printtxt(" We made it out!              ",0,-1)
            End If
            If ind = inimens+40 Then
                Printtxt("Barely(( but we did(          ",1,-1)
            End If
            If ind = inimens+100 Then
                Printtxt(" Now what is Next?            ",0,-1)
            End If
            If ind = inimens+150 Then
                Printtxt(" We keep going) together!!    ",1,-1)
            End If
        End If     
        Loop    
END Sub

'Mueve la nave por la pantalla
Sub mueveNave()
    If PX < 15 And ind>ininave Then      
        snd128(6)            
        PX = PX + 1
            
        putCharsOverMode(PX-2,PY,3,2,2,@nave_mask(Frame,0))     
    Else
        If ind>ininave
            waitretrace
            putCharsOverMode(PX,PY,1,2,2,@nave_mask(Frame,0))     
        End If
        WinScrollLeft(17,0,32,5)    
        ScrollLeft(0,127,255,171)    
        putChars(30,16,2,6,@hojas((ind mod 3)*12*8))
    End If

    If ind mod 40 = 1 Then
        putChars(27,3 + (ind mod 4),3,1,@skyNube2(0))
    End If
    If ind mod 70 = 1 Then
        putChars(27,3 + (ind mod 4),5,2,@skyNube1(0))
    End If

    If ind>ininave
        waitretrace
        putCharsOverMode(PX,PY,3,2,3,@nave_nave(Frame,0))     
    End If

    If Frame=3 Then
        Frame=0
    Else
        Frame=Frame+1
    End If
END Sub

'Imprime el texto del array txt
Sub Printtxt(text As STRING,tipo As UBYTE, pausa As BYTE)
    Dim i As UBYTE
    For i=0 To 29
        POKE @txt+i+30*3,CODE text(i)    
    Next i
    muthur(tipo,pausa,3)    
END Sub